//
//  BMortData.swift
//  BMort_Swift
//
//  Created by anscen on 2022/8/31.
//

import UIKit

class BMortData {
    static func insertData(model :BMortgage,completion:@escaping ((_ success : Bool) -> ())){
        BaseQueue().insertData(primaryId: model.identy, content: model.toJSONString() ?? "", completion: completion)
    }
    static func updateData(model :BMortgage,completion:@escaping ((_ success : Bool) -> ())){
        BaseQueue().updateData(primaryId: model.identy, content: model.toJSONString() ?? "", completion: completion)
    }
    static func deleteData(identy :String,completion:@escaping ((_ success : Bool) -> ())){
        BaseQueue().deleteData( primaryId: identy, completion: completion)
    }
    static func getData(identy :String,completion:@escaping ((_ model : BMortgage?) -> ())){
        BaseQueue().searchData(primaryId: identy) { datas in
            let listData = [BMortgage].deserialize(from: datas.rawString())
            if let list = listData,let model = list.first{
                completion(model)
            }else{
                completion(nil)
            }
        }
    }
}
